import request from '@/utils/request'
import http from '@/utils/http'

export function login(data) {
  return request({
    url: '/vue-admin-template/user/login',
    method: 'post',
    data
  })
}

// export function getInfo(token) {
//   return request({
//     url: '/vue-admin-template/user/info',
//     method: 'get',
//     params: { token }
//   })
// }

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}

/**
 * 获取用户列表
 * @param {*} param
 * @returns
 */
export const getListApi = async(param) => {
  return http.get('/api/user/list', param)
}

/**
 * 新增用户
 * @param {*} param
 * @returns
 */
export const addUserApi = async(param) => {
  return http.post('/api/user', param)
}

/**
 * 编辑用户
 * @param {*} param
 * @returns
 */
export const editUserApi = async(param) => {
  return http.put('/api/user', param)
}

/**
 * 删除用户
 * @param {*} param
 * @returns
 */
export const deleteUserApi = async(param) => {
  return http.delete('/api/user', param)
}

/**
 * 获取角色列表
 * @param {*} param
 * @returns
 */
export const getRoleListApi = async() => {
  return http.get('/api/user/roleList', null)
}

/**
 * 获取角色
 * @param {*} param
 * @returns
 */
export const getRoleApi = async(param) => {
  return http.get('/api/user/role', param)
}

/**
 * 用户登录
 * @param {*} param
 * @returns
 */
export const loginApi = async(param) => {
  return http.post('/api/login', param)
}

/**
 * 更新密码的 API 函数
 *
 */
export const updatePasswordApi = async(param) => {
  return http.post('/api/login/updatePassword', param)
}

/**
 * 获取用户信息
 * @param {*} param
 * @returns
 */
export const getInfoApi = async(param) => {
  return http.get('/api/login/getInfo', param)
}

/**
 * 获取主页统计信息的API
 *
 * @param param 请求参数
 * @returns Promise 返回一个Promise对象，resolve值为API的响应结果
 */
export const getHomeCountApi = async() => {
  return http.get('/api/login/getHomeCount', null)
}
